package com.d0306;

import java.util.Scanner;

public class Hero {
    int level;
    int exp;
    public Hero(int exp)
    {
        if(exp<0) {
            this.exp = 0;
            this.level = 0;
        }else if(exp>getMaxExp()) {
            this.exp = getMaxExp();
            this.level = getMaxLevel();
        }else{
            this.exp=exp;
            int level=0;
            while((exp=exp-getExp(level+1))>=0){
                level++;
            }
            this.level=level;
        }
    }
    public Hero(){
        this(0);
    }

    public int getExp(int level) {
        return  30*(level*level*level+5*level)-80;
    }
    public int getMaxLevel() {
        return 30;
    }
    public int getMaxExp() {
        return getExp(30);
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("无参数");
        Hero hero = new Hero();
        System.out.println(hero.exp);
        System.out.println(hero.level);
        System.out.println("有参数");
        Hero hero2 = new Hero(50000);
        System.out.println(hero2.exp);
        System.out.println(hero2.level);
    }
}
